package edu.upc.galaxy.dao.impl;


import edu.upc.galaxy.dao.*;
import edu.upc.galaxy.entity.Evento;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.stereotype.Repository;

/**
 *
 * @author ydb
 */
@Repository
public class EventoDaoImpl extends BaseDao {
    

    
    public Integer insertar(Evento evento) {
        String insert = "insert into evento(nombre,premio) values (?,?)";
        List list = new ArrayList();
        list.add(evento.getNombre());
        list.add(evento.getCodEvento());
        return this.insert(insert, list);
    }
    
    public void actualizar(Evento evento) {
        String update = "update evento set nombre = ?, premio = ? where id = ?";
        List list = new ArrayList();
        list.add(evento.getNombre());
        list.add(evento.getPremio());
        list.add(evento.getCodEvento());
        this.update(update, list);
    }
    
    public void eliminar(Evento evento) {
        String delete = "delete from evento where id = ?";
        this.delete(delete,evento.getCodEvento());
    }
    
    public List<Evento> buscar() {
        ResultSet rs = this.select("select * from evento");
        List<Evento> listado = new ArrayList<Evento>();
        try {
            while (rs.next()) {
                Evento evento = new Evento();
                evento.setCodEvento(rs.getInt(1));
                evento.setNombre(rs.getString(2));                
                listado.add(evento);
            }
        } catch (SQLException ex) {
            Logger.getLogger(CanchaDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return listado;
        
        
    }  
  
        
}
